<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Try it</title>
  </head>
  <body>
    <input type="button" id="id" name="Button 1" value="Something" />
    <script>
      // ---------------------------------------------------
      function sayHello() {
        alert('Hello');
        // ...更多语句...
      }

      // ---------------------------------------------------
      function doThis() {
        alert('Doing This');
      }

      function doHat() {
        alert('Doing That');
      }

      // ---------------------------------------------------
      sayHello();

      // ---------------------------------------------------
      function cube(x) {
        alert(x * x * x);
      }

      const length = 3;
      cube(length);

      // ---------------------------------------------------
      function times(a, b) {
        alert(a * b);
      }

      times(3, 4); // 显示'12'

      // ---------------------------------------------------
      function buttonReport(id, name, value) {
        // 按钮id信息
        const userMessage1 = `Button id: ${id}\n`;
        // 按钮名称
        const userMessage2 = `Button name: ${name}\n`;
        // 按钮值
        const userMessage3 = `Button value: ${value}\n`;
        // 提醒用户
        alert(userMessage1 + userMessage2 + userMessage3);
      }

      document.getElementById('id').addEventListener('click', function () {
        buttonReport(this.id, this.name, this.value);
      });

      // ---------------------------------------------------
      function cute2(x) {
        return x * x * x;
      }

      const answer = cube2(3);
      alert(cute2(3));

      // ---------------------------------------------------
      const sayHello = function () {
        alert('Hello');
      };
    </script>
  </body>
</html>
